package app.common.utils.cjt.vo;

import app.common.utils.NumberUtils;
import app.common.utils.cjt.ao.OtherDispatchCreateAo;
import app.common.utils.cjt.ao.ToOtherDispatchCreateAoDto;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 世界媒体峰会股票pd查询股票pd出详情响应对象
 * @author feizns
 * @since 2023/04/04
 */
@NoArgsConstructor
@Data
public class WmsStockPdQueryStockPdOutDetailVo {
    /**
     * total_count
     */
    private Integer total_count;
    /**
     * order
     */
    private List<Order> order;

    /**
     * Order
     */
    @NoArgsConstructor
    @Data
    public static class Order implements ToOtherDispatchCreateAoDto {
        /**
         * order_no
         */
        private String order_no;
        /**
         * consign_time
         */
        private Long consign_time;
        /**
         * receiver_province
         */
        private Integer receiver_province;
        /**
         * logistics_no
         */
        private String logistics_no;
        /**
         * receiver_city
         */
        private Integer receiver_city;
        /**
         * detail_list
         */
        private List<DetailList> detail_list;
        /**
         * receiver_district
         */
        private Integer receiver_district;
        /**
         * remark
         */
        private String remark;
        /**
         * goods_count
         */
        private Integer goods_count;
        /**
         * stockout_id
         */
        private Integer stockout_id;
        /**
         * receiver_mobile
         */
        private String receiver_mobile;
        /**
         * src_order_no
         */
        private String src_order_no;
        /**
         * operator_name
         */
        private String operator_name;
        /**
         * pd_order_remark
         */
        private String pd_order_remark;
        /**
         * warehouse_no
         */
        private String warehouse_no;
        /**
         * receiver_telno
         */
        private String receiver_telno;
        /**
         * receiver_zip
         */
        private String receiver_zip;
        /**
         * goods_total_cost
         */
        private String goods_total_cost;
        /**
         * receiver_name
         */
        private String receiver_name;
        /**
         * receiver_address
         */
        private String receiver_address;
        /**
         * receiver_country
         */
        private Integer receiver_country;
        /**
         * order_type
         */
        private Integer order_type;
        /**
         * status
         */
        private Integer status;

        @Override
        public OtherDispatchCreateAo.Dto toOtherDispatchCreateAo() {
            OtherDispatchCreateAo.Dto dto = new OtherDispatchCreateAo.Dto();
            dto.setExternalCode(this.getOrder_no());
            dto.setCode(this.getOrder_no());
            dto.setMemo("来源：[旺店通] 表单：[盘点出库单] 编号：[" + this.getOrder_no() + "] 备注:[" + this.getRemark() + "]");
            dto.setRdStyle(new OtherDispatchCreateAo.Dto.RdStyle("204"));
            dto.setVoucherType(new OtherDispatchCreateAo.Dto.VoucherType("ST1024"));
            dto.setVoucherDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date(this.getConsign_time())));
            dto.setBusiType(new OtherDispatchCreateAo.Dto.BusiType("13"));
            dto.setWarehouse(new OtherDispatchCreateAo.Dto.Warehouse(this.getWarehouse_no()));
            dto.setRDRecordDetails(this.detail_list.stream().map(DetailList::toRDRecordDetails).collect(Collectors.toList()));
            return dto;
        }

        /**
         * DetailList
         */
        @NoArgsConstructor
        @Data
        public static class DetailList {
            /**
             * rec_id
             */
            private Integer rec_id;
            /**
             * stockout_id
             */
            private Integer stockout_id;
            /**
             * spec_no
             */
            private String spec_no;
            /**
             * goods_count
             */
            private Integer goods_count;
            /**
             * remark
             */
            private String remark;
            /**
             * brand_no
             */
            private String brand_no;
            /**
             * brand_name
             */
            private String brand_name;
            /**
             * goods_name
             */
            private String goods_name;
            /**
             * goods_no
             */
            private String goods_no;
            /**
             * spec_name
             */
            private String spec_name;
            /**
             * spec_code
             */
            private String spec_code;
            /**
             * defect
             */
            private Boolean defect;
            /**
             * cost_price
             */
            private Double cost_price;
            /**
             * weight
             */
            private Integer weight;
            /**
             * goods_type
             */
            private Integer goods_type;
            /**
             * unit_name
             */
            private String unit_name;
            /**
             * batch_no
             */
            private String batch_no;

            public OtherDispatchCreateAo.Dto.RDRecordDetails toRDRecordDetails() {
                OtherDispatchCreateAo.Dto.RDRecordDetails details = new OtherDispatchCreateAo.Dto.RDRecordDetails();
                details.setInventory(new OtherDispatchCreateAo.Dto.RDRecordDetails.Inventory(this.spec_no));
//                details.setInvLocation(new OtherDispatchCreateAo.Dto.RDRecordDetails.InvLocation(this));
                details.setBaseQuantity(BigDecimal.valueOf(Double.valueOf(this.goods_count)));
                details.setPrice(NumberUtils.fourDecimalPlaces(BigDecimal.valueOf(this.cost_price / this.goods_count)));
                details.setAmount(BigDecimal.valueOf(this.cost_price));
                System.out.println(details.getAmount());
                return details;
            }
        }
    }
}
